<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>旅馆设置</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <script type="text/javascript" src="../../script/aes.js"></script>
	<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
	<script type="text/javascript" src="../../script/modeecb.js"></script>
    <script type="text/javascript" src="../../script/tmd5.js"></script>
    <script type="text/javascript" src="../../script/constants.js"></script>
    <script type="text/javascript" src="../../resource/jquery214.js"></script>
    <script src="../../script/api.js"></script>
    <style>
    	body{
    	    margin: 0;	
    	    background:url(../../image/bj.png) repeat-x 0;
    	    background-size: 100%;
    	}
    	.title{
    	    height: 45px;
    	    background: #0483d3;
    	    line-height: 45px;
    	    font-size: 20px;
    	    margin-bottom: 20px;
    	}
    	
    	.input{
	    	float:left;
	    	width: 25%;
	    	height: 30px;
	    	padding: 5px;
	    	font-size: 16px;
	    	border:0;
	    	outline:none;
	    	border-radius: 5px;
    	}
    	.text{
	    	float: left;
	    	height: 30px;
	    	line-height: 30px;
	    	font-size: 18px;
	    	color: #666666;
	    	padding: 5px;
	    	text-align: center;
    	}
    </style>
</head>
<body>
<header id="statusBar">
  <div class="title">
    <div style="float: left;width: 30px;height: 30px;padding: 7.5px;" onclick="api.closeWin();">
    <img src="../../image/hotelManage/back.png"  style="width: 100%;"/>
    </div>
    <div style="float: left;color: #ffffff;">
    旅馆设置
    </div>
    <div style="float: right;color: #32CD32;margin-right: 20px;" onclick="setHotel();">
    完成
    </div>
  </div>
  </header>
  <div>
   <div style="">
    <div style="width: 30%;" class="text">旅馆名称：</div>
    <input type="text" class="input" style="width: 60%" placeholder="请输入旅馆名称" id="hotelName"/>
   </div>
   <div style="height: 10px;clear: both;"></div>
   
   <div style="">
    <div style="width: 30%;" class="text">旅馆编号：</div>
    <input type="text" class="input" style="width: 60%" placeholder="请输入旅馆编号" id="hotelNum"/>
    <div style="height: 10px;clear: both;"></div>
   </div>
  </div>      
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
	apiready = function(){
	
	    if(api.systemType == "ios"){
		   document.getElementById("statusBar").style.background = "#298cb4";
		}
	    $api.fixStatusBar( $api.dom('header') );
	    
	    var phone = $api.getStorage("dl_phone");
        var callback = function(ret, err){
	        if(ret){
	           if(ret.code == 0){
	              $api.setStorage("hotelId",ret.STATIONID);
	              $("#hotelName").val(ret.HOTELNAME);
	              $("#hotelNum").val(ret.STATIONID);
	           }else if(ret.code == 1){
	              api.alert({msg: "授权已不足15天，截止日期为："+ret.EDATE});
	              $("#hotelName").val(ret.HOTELNAME);
	              $("#hotelNum").val(ret.STATIONID);
	           }else if(ret.code == 98){
	              api.alert({msg: "未到授权日期，开始时间为："+ret.SDATE});
	              api.closeWin();
	           }else if(ret.code == 97){
	              api.alert({msg: "授权已过期，请联系工作人员"});
	              api.closeWin();
	           }else if(ret.code == 96){
	              //未找到旅馆信息
	           }else{
	              api.alert({msg: "数据异常，请联系工作人员"});
	              api.closeWin();
	           }
	        }else{
	           api.alert({msg: JSON.stringify(err)});
	        }
	    }
	    var content = {"phone":phone};
	    apiAjax(JSON.stringify(content),url.hotelInfo,callback);
	};
	
	
	function setHotel(){
	   var uiId;
       var UILoading = api.require('UILoading');
	   UILoading.flower({
		    center: {
		        x: api.winWidth/2.0,          
		        y: api.winHeight/2.0 
		    },
		    size: 30,
		    mask: "rgba(0,0,0,0.5)",
		    fixed: true
	   }, function(ret) {
		    //alert(JSON.stringify(ret));
		    uiId = ret.id;
	   });
	    var phone = $api.getStorage("dl_phone");
	    var hotelName = $("#hotelName").val();
	    var hotelNum = $("#hotelNum").val();
	    var callback = function(ret, err){
	        UILoading.closeFlower({
				    id: uiId
			});
	        if(ret){
	        console.log(JSON.stringify(ret));
	           if(ret.code == 0 || ret.code == 1){
	              api.alert({msg: "设置成功"});
	           }else if(ret.code == 98){
	              api.alert({msg: "未查询到该旅馆授权信息"});
	           }else{
	              api.alert({msg: ret.msg});
	           }
	        }else{
	           api.alert({msg: JSON.stringify(err)});
	        }
	    }
	    var content = {"hotelId":hotelNum,"phone":phone};
	    apiAjax(JSON.stringify(content),url.setHotel,callback);
	    
	}
</script>
</html>